#ifndef _COMPASS_H
#define _COMPASS_H
#include "at32f435_437.h"
#include "inv_mpu.h"
#include <stdlib.h>
#include <math.h>
#include "Ellipsoid_Fitting.h"
#include "Smooth_Filter.h"


#define COMPASS_TEST 0

#define FILTER_NUM 10

#if COMPASS_TEST
#include "SEGGER_RTT.h"
#endif


typedef struct
{
	short Compass_Data[3];
	short Accel_Data[3];
	
	//磁力计 单位：uT
	float Compass_x;
	float Compass_y;
	float Compass_z;
	
	//加速度 单位：m/s^2
	float Accel_x;
	float Accel_y;
	float Accel_z;
	
	float X_uT;
	float Y_uT;
	float Z_uT;

}Base_Data_t;

typedef struct
{
 	float X_Max;
	float X_Min;
	float X_Offset;

	float Y_Max;
	float Y_Min;
	float Y_Offset;


}Level_Data_t;

typedef struct
{
	const Ellipsoid_fitting_Data_t* Ellipsoid_fitting_Data;
	SmoothFilter_t SmoothFilter;
  Base_Data_t Base_Data;
	Level_Data_t Level_Data;

	float IMU_Pitch;
	float IMU_Roll;
	float IMU_Yaw;
	
  float Rate_Data;
	float X_H;
	float Y_H;

	float Compass_Angle;
	float Compass_Angle_Filter;
	
}Compass_Data_t;
void Compass_Init_Filter(Compass_Data_t *Compass_Data);
void Compass_Data_Init(Compass_Data_t *Compass_Data);
void Compass_Data_Processing(Compass_Data_t *Compass_Data);
void Ellipsoid_fitting_Init(Compass_Data_t *Compass_Data);
uint8_t FindString(const char * pBuf, uint8_t *pindex, uint8_t compare_len, char new_byte);


#endif


